/*     */ package com.newcrm.businessarchives;
/*     */ 
/*     */ import com.newcrm.exception.CaptchaException;
/*     */ import com.newcrm.util.Util;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.lang.StringEscapeUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ import org.jsoup.nodes.Element;
/*     */ import org.jsoup.select.Elements;
/*     */ 
/*     */ public class AnhuiSearchEngine extends SearchEngine
/*     */ {
/*  22 */   private static Logger logger = Logger.getLogger(AnhuiSearchEngine.class
/*  23 */     .getName());
/*     */ 
/*  25 */   private Map<String, String> params = new HashMap();
/*     */ 
/*     */   public AnhuiSearchEngine(String name) {
/*  28 */     this.name = standardizedName(name);
/*  29 */     this.params.put("企业名称：", "CompanyName");
/*  30 */     this.params.put("企业名称", "CompanyName");
/*  31 */     this.params.put("注册号：", "SN");
/*  32 */     this.params.put("注册号", "SN");
/*  33 */     this.params.put("法定代表人（负责人）：", "Header");
/*  34 */     this.params.put("法定代表人", "Header");
/*  35 */     this.params.put("成立日期：", "FoundedDate");
/*  36 */     this.params.put("创建日期", "FoundedDate");
/*  37 */     this.params.put("企业类型：", "CompanyType");
/*  38 */     this.params.put("企业类型（中类）", "CompanyType");
/*  39 */     this.params.put("注册资本：", "RegisteredCapital");
/*  40 */     this.params.put("注册资本(金)", "RegisteredCapital");
/*  41 */     this.params.put("登记机关：", "RegistrationAuthority");
/*  42 */     this.params.put("管辖单位", "RegistrationAuthority");
/*  43 */     this.params.put("经营场所：", "Address");
/*  44 */     this.params.put("经营地址", "Address");
/*  45 */     this.params.put("经营期限起：", "OperatingPeriodStart");
/*  46 */     this.params.put("经营期限起", "OperatingPeriodStart");
/*  47 */     this.params.put("经营期限止：", "OperatingPeriodEnd");
/*  48 */     this.params.put("经营期限止", "OperatingPeriodEnd");
/*  49 */     this.params.put("经营范围：", "BusinessScope");
/*  50 */     this.params.put("经营范围", "BusinessScope");
/*     */   }
/*     */ 
/*     */   public static void main(String[] args)
/*     */     throws CaptchaException
/*     */   {
/*  63 */     AnhuiSearchEngine searchEngine = new AnhuiSearchEngine("安徽新美达信息科技有限公司");
/*     */ 
/*  65 */     Map items = searchEngine.getCompanyByWeb();
/*  66 */     System.out.println(items);
/*     */   }
/*     */ 
/*     */   protected Map<String, Object> getCompanyByWeb()
/*     */     throws CaptchaException
/*     */   {
/*  74 */     if (!isValid(this.name)) {
/*  75 */       return null;
/*     */     }
/*  77 */     String url = null;
/*     */     try {
/*  79 */       url = "http://218.22.14.69:8085/topbirt/run?zch=&fddbr=&__balance_unit=%25E5%2585%2583&__report=%2Fqycx.rptdesign&__page=-1&__actionFlag=getResultFrame&__pageButtonFlag=&__exportFileType=&__exportPageNos=&__exportCSVTableName=&__exportCSVColumns=&__exportCSVEncoding=&__exportCSVSeperator=&__printPageType=&__printPageNos=&__extJsGridCookie=&__mainReportQuery=true&__screenWidth=1440&qymc=" + URLEncoder.encode(this.name.trim(), "gb2312");
/*     */     } catch (UnsupportedEncodingException e) {
/*  81 */       url = "http://218.22.14.69:8085/topbirt/run?zch=&fddbr=&__balance_unit=%25E5%2585%2583&__report=%2Fqycx.rptdesign&__page=-1&__actionFlag=getResultFrame&__pageButtonFlag=&__exportFileType=&__exportPageNos=&__exportCSVTableName=&__exportCSVColumns=&__exportCSVEncoding=&__exportCSVSeperator=&__printPageType=&__printPageNos=&__extJsGridCookie=&__mainReportQuery=true&__screenWidth=1440&qymc=" + this.name.trim();
/*     */     }
/*     */     try {
/*  84 */       Document doc = Jsoup.connect(url).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)")
/*  85 */         .timeout(10000).get();
/*  86 */       Elements links = doc
/*  87 */         .select("table[id=AUTOGENBOOKMARK_1] tr td div a");
/*  88 */       String detailUrl = null;
/*  89 */       if ((links != null) && (links.size() >= 1)) {
/*  90 */         detailUrl = links.get(0).absUrl("href");
/*     */       }
/*     */ 
/*  93 */       if ((detailUrl == null) || (detailUrl.trim().length() == 0))
/*     */       {
/*  95 */         return getCompanyByWeb2();
/*     */       }
/*     */ 
/*  99 */       doc = Jsoup.connect(detailUrl).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000)
/* 100 */         .get();
/* 101 */       links = doc.select("table[id=AUTOGENBOOKMARK_1] td[align=right]");
/* 102 */       if (links == null) {
/* 103 */         return null;
/*     */       }
/*     */ 
/* 106 */       Map info = new HashMap();
/* 107 */       for (Element item : links) {
/* 108 */         String key = StringEscapeUtils.unescapeHtml(item.text().trim());
/* 109 */         if (this.params.containsKey(key))
/*     */         {
/* 112 */           info.put((String)this.params.get(key), 
/* 113 */             StringEscapeUtils.unescapeHtml(item.nextElementSibling().text()));
/*     */         }
/*     */       }
/* 115 */       info.put("OperatingPeriod", info.get("OperatingPeriodStart") + " - " + 
/* 116 */         info.get("OperatingPeriodEnd"));
/* 117 */       info.put("UpdateDate", Util.date2Str(new Date()));
/* 118 */       if (info.size() > 1)
/*     */       {
/* 120 */         saveDB(info);
/*     */       }
/*     */ 
/* 123 */       return info;
/*     */     } catch (IOException e) {
/* 125 */       logger.warn("get company from web failed", e);
/*     */     }
/*     */ 
/* 128 */     return null;
/*     */   }
/*     */ 
/*     */   private Map<String, Object> getCompanyByWeb2() {
/* 132 */     String url = null;
/*     */     try {
/* 134 */       url = "http://www.hdfw.net.cn/srch.jsp?select=mc&ipt=" + URLEncoder.encode(this.name.trim(), "gb2312");
/*     */     } catch (UnsupportedEncodingException e) {
/* 136 */       url = "http://www.hdfw.net.cn/srch.jsp?select=mc&ipt=" + this.name.trim();
/*     */     }
/*     */     try {
/* 139 */       Document doc = Jsoup.connect(url).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)")
/* 140 */         .timeout(10000).get();
/* 141 */       Elements links = doc.select("tr td[colspan=2]");
/*     */ 
/* 143 */       if ((links == null) || (links.size() == 0)) {
/* 144 */         return null;
/*     */       }
/* 146 */       String detailUrl = null;
/*     */       Elements e;
/* 147 */       for (Element link : links) {
/* 148 */         e = link.select("a");
/* 149 */         if (e != null)
/*     */         {
/* 152 */           String companyName = e.first().text();
/* 153 */           if ((companyName != null) && (companyName.trim().length() != 0))
/*     */           {
/* 157 */             if (companyName.equals(this.name)) {
/* 158 */               detailUrl = e.first().absUrl("href");
/* 159 */               break;
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/* 163 */       if ((detailUrl == null) || (detailUrl.trim().length() == 0)) {
/* 164 */         return null;
/*     */       }
/*     */ 
/* 168 */       doc = Jsoup.connect(detailUrl).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000)
/* 169 */         .get();
/* 170 */       links = doc.select("table tr td[class=nameList]");
/* 171 */       if (links == null) {
/* 172 */         return null;
/*     */       }
/*     */ 
/* 176 */       Map info = new HashMap();
/* 177 */       for (Element item : links) {
/* 178 */         String key = item.text().trim();
/* 179 */         if (this.params.containsKey(key))
/*     */         {
/* 182 */           info.put((String)this.params.get(key), item.nextElementSibling().text());
/*     */         }
/*     */       }
/* 184 */       info.put("OperatingPeriod", info.get("OperatingPeriodStart") + " - " + 
/* 185 */         info.get("OperatingPeriodEnd"));
/* 186 */       info.put("UpdateDate", Util.date2Str(new Date()));
/* 187 */       if (info.size() > 1)
/*     */       {
/* 189 */         saveDB(info);
/*     */       }
/*     */ 
/* 192 */       return info;
/*     */     } catch (IOException e) {
/* 194 */       logger.warn("get company from web failed", e);
/*     */     }
/*     */ 
/* 197 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.AnhuiSearchEngine
 * JD-Core Version:    0.6.1
 */